﻿using ReporterSystem;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace ReportSystemTest
{
    
    
    /// <summary>
    ///This is a test class for ReportAppTest and is intended
    ///to contain all ReportAppTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ReportAppTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public void deleteTestProjects()
        {
            string myDocumentsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Provision Reports");

            foreach(var folder in Directory.GetDirectories(myDocumentsFolder, "test*test", SearchOption.TopDirectoryOnly))
            {
                Directory.Delete(folder,true);
            }
        }

        /// <summary>
        ///A test for CreateReportProject
        ///</summary>
        [TestMethod()]
        public void CreateReportProjectTest()
        {
            deleteTestProjects();

           // ReportApp target = new ReportApp(); // TODO: Initialize to an appropriate value
            ReportProject project = new ReportProject { Name = "test CreateReportProjectTest test"};
            project.Notebook.NotebookName = "iBPM (4)";

            project.Templates.Add(new ReportTemplate{TemplateFileName = "tpl1",ResultFileName = "res1"});
            project.Templates.Add(new ReportTemplate { TemplateFileName = "tpl2", ResultFileName = "res2" });
            project.Templates.Add(new ReportTemplate { TemplateFileName = "tpl3", ResultFileName = "res3" });

            ReportApp.CreateReportProject(project);

            var result = ReportApp.CheckIfExistsReportProjectName(project.Name);

            Assert.IsTrue(result,"problem to create project");


            //test inner projects items
            var newTemplate1 = new ReportTemplate {TemplateFileName = "new tpl5", ResultFileName = "new res5"};

            ReportApp.CreateTemplate(newTemplate1, project);


            //target.DeleteReportProject(project);

            //result = target.CheckIfExistsReportProjectName(project.Name);

            //Assert.IsFalse(result,"problem to delete project");
        }
    }
}
